package com.lemon.smartsafetynew.ui.adapter.patrol;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.patrol.SafePatrolHistoryItemVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2017/8/3.
 */

public class PatrolHistoryAdapter extends LemonRcvAdapter<SafePatrolHistoryItemVo> {

    private RecyclerTClickListener<SafePatrolHistoryItemVo> mListener;

    public PatrolHistoryAdapter(@Nullable List<SafePatrolHistoryItemVo> data,
                                RecyclerTClickListener<SafePatrolHistoryItemVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new SafePatrolItem();
    }

    private class SafePatrolItem implements AdapterItem<SafePatrolHistoryItemVo> {

        private TextView safePatrolWorkerTv;
        private TextView safePatrolTimeTv;
        private TextView passStatusTv;
        private TextView failStatusTv;
        private LinearLayout safePatrolHistoryLayout;

        private SafePatrolHistoryItemVo mData;
        private int mPosition;

        @Override
        public int getLayoutResId() {
            return R.layout.item_safe_patrol_history;
        }

        @Override
        public void bindViews(View root) {
            safePatrolWorkerTv = (TextView) root.findViewById(R.id.safe_patrol_worker_tv);
            safePatrolTimeTv = (TextView) root.findViewById(R.id.safe_patrol_time_tv);
            passStatusTv = (TextView) root.findViewById(R.id.pass_status_tv);
            failStatusTv = (TextView) root.findViewById(R.id.fail_status_tv);
            safePatrolHistoryLayout = (LinearLayout) root.findViewById(R.id.safe_patrol_hisory_layout);
        }

        @Override
        public void setViews() {

            safePatrolHistoryLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(mData, mPosition);
                }
            });

        }

        @Override
        public void handleData(SafePatrolHistoryItemVo historyItemVo, int position) {

            mPosition = position;
            mData = historyItemVo;

            safePatrolWorkerTv.setText(historyItemVo.getCheck_user_name());
            safePatrolTimeTv.setText(CommonUtil.timeToStr(historyItemVo.getCheck_date()));

            if(CommonUtil.stringEqualsForBigInteger("1", historyItemVo.getStatus())) {
                passStatusTv.setVisibility(View.VISIBLE);
                passStatusTv.setText("本次检查通过");
                failStatusTv.setVisibility(View.GONE);
            } else {
                failStatusTv.setVisibility(View.VISIBLE);
                failStatusTv.setText("本次检查未通过");
                passStatusTv.setVisibility(View.GONE);
            }

        }

    }
}
